﻿using System;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System.Collections.Generic;

namespace mvcForum.MembershipProviderTest {

	public class User {
		public ObjectId Id { get; set; }
		[BsonElement(FieldNames.CreationDate)]
		public DateTime CreationDate { get; set; }
		[BsonElement(FieldNames.Email)]
		public String Email { get; set; }
		[BsonElement(FieldNames.FailedPasswordAttemptCount)]
		public Int32 FailedPasswordAttemptCount { get; set; }
		[BsonElement(FieldNames.FailedPasswordAttemptWindowStart)]
		public DateTime FailedPasswordAttemptWindowStart { get; set; }
		[BsonElement(FieldNames.IsApproved)]
		public Boolean IsApproved { get; set; }
		[BsonElement(FieldNames.IsLockedOut)]
		public Boolean IsLockedOut { get; set; }
		[BsonElement(FieldNames.LastActivityDate)]
		public DateTime LastActivityDate { get; set; }
		[BsonElement(FieldNames.LastLockoutDate)]
		public DateTime LastLockoutDate { get; set; }
		[BsonElement(FieldNames.LastLoginDate)]
		public DateTime LastLoginDate { get; set; }
		[BsonElement(FieldNames.LastPasswordChangedDate)]
		public DateTime LastPasswordChangedDate { get; set; }
		[BsonElement(FieldNames.Password)]
		public String Password { get; set; }
		[BsonElement(FieldNames.Salt)]
		public String Salt { get; set; }
		[BsonElement(FieldNames.Username)]
		public String Username { get; set; }
		[BsonElement(FieldNames.ApplicationName)]
		public String ApplicationName { get; set; }
		[BsonElement(FieldNames.UpperUsername)]
		public String UpperUsername { get; set; }

		[BsonElement(FieldNames.Roles)]
		public IList<String> Roles { get; set; }

		//[BsonIgnoreIfNull]
		//[BsonElement(FieldNames.Identity)]
		//public Identity Identity { get; set; }

		[BsonIgnoreIfNull]
		[BsonElement(FieldNames.Profile)]
		public UserProfile Profile { get; set; }

		public User() {
			this.Roles = new List<String>();
		}

		public override string ToString() {
			//return this.Identity == null ? this.Username : String.Format("{0};{1};{2}", this.Username, this.Identity.Ident, this.Identity.ProviderName);
			return this.Username;
		}

		public static class FieldNames {
			public const String Id = "_id";
			public const String CreationDate = "creation";
			public const String Email = "email";
			public const String FailedPasswordAttemptCount = "fpac";
			public const String FailedPasswordAttemptWindowStart = "fpaws";
			public const String IsApproved = "approved";
			public const String IsLockedOut = "locked";
			public const String LastActivityDate = "lastactivity";
			public const String LastLockoutDate = "lastlockout";
			public const String LastLoginDate = "lastlogin";
			public const String LastPasswordChangedDate = "lastpwchange";
			public const String Password = "password";
			public const String Salt = "salt";
			public const String Username = "username";
			public const String ApplicationName = "app";
			public const String UpperUsername = "uusername";
			public const String Roles = "roles";
			public const String Profile = "profile";
			public const String Identity = "ident";
		}
	}
}
